package com.junlong0716.enjoylearning.adapter

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.junlong0716.enjoylearning.R
import com.junlong0716.enjoylearning.entity.ClassifyEntity
import com.junlong0716.enjoylearning.ui.ClassifyDetailActivity
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter
import com.zhy.view.flowlayout.TagFlowLayout

/**
 *@author: 巴黎没有摩天轮Li
 *@description:
 *@date: Created in 下午9:41 2018/5/4
 *@modified by:
 */
class ClassifyAdapter(data: ArrayList<ClassifyEntity>, resLayout: Int) : BaseQuickAdapter<ClassifyEntity, BaseViewHolder>(resLayout, data) {
    override fun convert(helper: BaseViewHolder?, item: ClassifyEntity?) {
        helper!!.setText(R.id.tv_title, item!!.classifyName)
        var tagFlowLayout = helper.getView<TagFlowLayout>(R.id.flow_layout)
        tagFlowLayout.adapter = object : TagAdapter<ClassifyEntity.DetailsBean>(item.details) {
            override fun getView(parent: FlowLayout?, position: Int, t: ClassifyEntity.DetailsBean?): View {
                var tagView = LayoutInflater.from(mContext).inflate(R.layout.item_tag, null)
                var tvTag = tagView.findViewById<TextView>(R.id.tv_tag)
                tvTag.text = t!!.classifyName
                return tagView
            }
        }
        tagFlowLayout.setOnTagClickListener { view, position, parent ->
            val intent = Intent(mContext,ClassifyDetailActivity::class.java)
            intent.putExtra("CLASSIFY_NAME",item.details[position].classifyName)
            intent.putExtra("CLASSIFY_ID",item.details[position].id)
            mContext.startActivity(intent)
            return@setOnTagClickListener true
        }
    }
}